﻿@{
    ViewData["Title"] = "Index";
    Layout = "~/Areas/Console/Views/Shared/_Layout.cshtml";
}
@section head{
    <script type="text/javascript">
        var renderTable;
        layui.config({
            base: '../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'table', 'form'], function () {
            var $ = layui.$
                , form = layui.form
                , admin = layui.admin
                , table = layui.table;

            renderTable = function () {
                table.render({
                    elem: '#table-datalist'
                    , url: '/Console/ExchangeRate/GetListJson'
                    , title: '数据表'
                    , cols: [[
                        { type: 'checkbox', fixed: 'left' }
                        , { field: 'index', title: '序号', type: 'numbers', width: 60, templet: '#zizeng' }
                        , { field: 'fromCurrency', title: '转入货币' }
                        , { field: 'toCurrency', title: '转出货币' }
                        , {
                            field: 'updateType', title: '更新模式', templet: function (res) {
                                if (res.updateType == 1)
                                    return '<span lay-event="autoUpdate"></span>'
                                else
                                    return '<span lay-event="manualUpdate"></span>'
                            }
                        }
                        , { field: 'price', title: '价格' }
                        , { field: 'buyDownFloat', title: '买入下浮' }
                        , { field: 'sellUpFloat', title: '卖出上浮' }
                        , { field: 'updatetime', title: '更新时间' }
                        , { fixed: 'right', title: '操作', toolbar: '#table-datalist-bar' }
                    ]]
                    , page: { layout: ['prev', 'page', 'next', 'refresh'] }
                    , done: function (res) {
                        if (res.count == 0) {
                            $(".layui-table-main").html('<div class="layui-none">' + top.lang.noData + '</div>');
                        }
                        layer.closeAll('loading');

                        /**多语言初始化 */
                        top.SetListPageLanguage(layui);
                    }
                });
            };
            //加载表格
            renderTable();

            //监听行工具事件
            table.on('tool(table-datalist)', function (obj) {
                var data = obj.data;
                if (obj.event === 'del') {
                    var postData = {
                        fromCurrency: data.fromCurrency,
                        toCurrency: data.toCurrency
                    };
                    top.ConfirmByKey(layui, 'confirmDelete', postData, "/Console/ExchangeRate/Delete", "POST", "deleteSuccess", "deleteFail", function () {
                        renderTable();
                    });
                } else if (obj.event === 'edit') {
                    top.OpenPageByKey(layui, "edit", 2, '600px', '550px', '/Console/ExchangeRate/Edit?id=' + data.id);
                }
            });
            form.on('submit(addNew)', function (data) {
                top.OpenPageByKey(layui, "addNew", 2, '600px', '550px', '/Console/ExchangeRate/Create');
            });
        });
    </script>
}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-table-tool layui-form" style="box-sizing: border-box;">
                        <div class="layui-table-tool-temp">
                            <button type="button" class="layui-btn layui-btn-sm" id="addNew" lay-submit lay-filter="addNew">新增</button>
                        </div>
                    </div>
                    <table class="layui-hide" id="table-datalist" lay-filter="table-datalist"></table>
                    <script type="text/html" id="zizeng">
                        {{d.LAY_TABLE_INDEX+1}}
                    </script>
                    <script type="text/html" id="table-datalist-bar">
                        <button class="layui-btn layui-btn-xs" lay-event="edit">编辑</button>
                        <button class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div>